﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using Telerik.Web.UI;
using KPIS.GERP.GIMS.DAL;
using KPIS.GERP.GIMS.MODEL;

namespace KPIS.GERP.GIMS.APP.APP_UI.Edit_Form
{
    public partial class ICM_Requisition_Approve : System.Web.UI.Page
    {
        Common.Main cn = new Common.Main();
        M_Requisition m_request = new M_Requisition();
        D_Requisition d_request = new D_Requisition();
        D_Requisition_Desc d_request_desc = new D_Requisition_Desc();
        M_Requisition_Desc m_request_desc = new M_Requisition_Desc();

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                pRequisitionCode.Text = Request.QueryString["Requsition_Code"];//"RQ2554-02-00050";
                LoadGrid();
                LoadToObject();
                grdRequisition.DataBind();
            }
        }
        protected void grdRequisition_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
        {
            LoadGrid();
            grdRequisition.DataBind();
        }
        private void LoadGrid()
        {
            grdRequisition.DataSource = d_request_desc.GetListFillCode(pRequisitionCode.Text);
        }
        private void LoadToObject()
        {
            M_Requisition info = d_request.GetListFillBySeq(pRequisitionCode.Text);
            pRequisitionCode.Text = info.requisition_code;
            pRequisitionDate.Text = info.requisition_date.ToShortDateString() ;
            pEmployeeName.Text = info.employee_name;
            pOrganizeName.Text = info.job_site_name;
            pDescriptionRequest.Text = info.description;
            pRemark.Text = info.remark;
        }
        protected void btnApprove_Click(object sender, EventArgs e)
        {
            m_request.requisition_code = pRequisitionCode.Text;
            m_request.approve_flag = 1;
            m_request.approve_emp_seq = cn.ApproveID;
            m_request.approve_when = DateTime.Now;
            d_request.Approve_Requisition(m_request);
            RadAjaxManager1.ResponseScripts.Add(@"CloseWindow();");
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            m_request.requisition_code = pRequisitionCode.Text;
            m_request.cancel_flag = 1;
            m_request.cancel_by = cn.ApproveID;
            m_request.cancel_when = DateTime.Now;
            m_request.cancel_remark = txtRemarkCancel.Text ;
            d_request.Cancel_Requisition(m_request);
            RadAjaxManager1.ResponseScripts.Add(@"CloseWindow();");
        }
    }
}
